<?php
class route {
	
	// site routes
	private static $routes = array(
	
		// page module
		"about" => "page/about",
		"faq" => "page/faq",
		"contact" => "page/contact",
		"disclaimer" => "page/disclaimer",
		"helppromote" => "page/helppromote",
		"bannersandlogos" => "page/bannersandlogos",
	
		// user module
		"profile" => "user/profile",
		"enhance" => "user/enhance",
		"register" => "user/register",
		"logout" => "user/logout",
		"logon" => "user/logon",
	
		// landing pages
		"amariszi" => "landing/amariszi"
	);
	
	public static function buildRoute($request) {
		$ret = $request["module"];
		if (isset($request["action"])) {
			$ret .= "/" . $request["action"];
			if (isset($request["format"])) {
				$ret .= "/" . $request["format"];
			}
		}
		return $ret;		
	}
	
	public static function buildRequest($route) {
		$elm = explode("/", $route);
		$ret = array("module" => $elm[0]);
		if (isset($elm[1])) {
			$ret["action"] = $elm[1];
			if (isset($elm[2])) {
				$ret["format"] = $elm[2];
			}
		}
		return $ret;
	}
	
	public static function getRoutedRequest($request) {
		$route = self::buildRoute($request);
		if (array_key_exists($route, self::$routes)) {
			return self::buildRequest(self::$routes[$route]);
		} else {
			return $request;
		}
	}
}
?>